package com.huxianyang.controller;

import com.huxianyang.bean.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 
 * @since 2022/06/01 22:02
 * @author HuXianyang
 */
@RestController
public class UserController {
    @RequestMapping("login")
    public String login(User user, HttpSession session) {
        if ("admin".equals(user.getUsername()) && "admin".equals(user.getPassword())){
            session.setAttribute("user",user);
            // 我们会返回json字符串而不是string，所以不必纠结string乱码问题
            return "登录成功!";
        }
        return "登录失败，请检查用户名和密码！";
    }

    @RequestMapping("hello")
    public String hello() {
        return "hello";
    }
}